import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-n', '--npu_nums', type=int, default='2', help='nums of npu')
parser.add_argument('-c', '--conf_path', type=str, default='./', help='the path of server_info')
FLAGS = parser.parse_args()

import json
import os
server = []
server_conf = []
server_list = ["0", "1", "2", "3", "4", "5", "6", "7"]
if os.path.isdir(FLAGS.conf_path):
	for f in os.listdir(FLAGS.conf_path):
		if (f.split("_")[-1]).split(".")[0] in server_list and (f.split("_")[-1]).split(".")[1] == 'info' and f.split("_")[0] == 'server':
			server_conf.append(f)
			





rank_address = []
for i in range(FLAGS.npu_nums):
	for x in server_conf:
		if (x.split("_")[-1]).split(".")[0] == str(i):
			server.append(x.split("_")[1])
			l = FLAGS.conf_path + "/" + x
			with open(l, "r") as a:
				s = a.readlines()
				for s_ in s:
					if 'address_0' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_1' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_2' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_3' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_4' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_5' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_6' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
				for s_ in s:
					if 'address_7' in s_:
						rank_address.append(s_.split("=")[-1][:-1])
			
if FLAGS.npu_nums == 1:
	rank = {
		"server_count":"1",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]}],
		"status":"completed",
		"version":"1.0"
	}
elif FLAGS.npu_nums == 2:
	rank = {
		"server_count":"2",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]}
				],
		
		"status":"completed",
		"version":"1.0"
	}
	
	
elif FLAGS.npu_nums == 3:
	rank = {
		"server_count":"3",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}
elif FLAGS.npu_nums == 4:
	rank = {
		"server_count":"4",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]},
				{
				"server_id":server[3],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[24],
						"rank_id":"24"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[25],
						"rank_id":"25"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[26],
						"rank_id":"26"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[27],
						"rank_id":"27"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[28],
						"rank_id":"28"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[29],
						"rank_id":"29"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[30],
						"rank_id":"30"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[31],
						"rank_id":"31"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}
elif FLAGS.npu_nums == 5:
	rank = {
		"server_count":"5",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]},
				{
				"server_id":server[3],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[24],
						"rank_id":"24"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[25],
						"rank_id":"25"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[26],
						"rank_id":"26"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[27],
						"rank_id":"27"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[28],
						"rank_id":"28"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[29],
						"rank_id":"29"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[30],
						"rank_id":"30"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[31],
						"rank_id":"31"
					}
				]},
				{
				"server_id":server[4],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[32],
						"rank_id":"32"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[33],
						"rank_id":"33"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[34],
						"rank_id":"34"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[35],
						"rank_id":"35"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[36],
						"rank_id":"36"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[37],
						"rank_id":"37"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[38],
						"rank_id":"38"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[39],
						"rank_id":"39"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}



elif FLAGS.npu_nums == 6:
	rank = {
		"server_count":"6",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]},
				{
				"server_id":server[3],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[24],
						"rank_id":"24"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[25],
						"rank_id":"25"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[26],
						"rank_id":"26"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[27],
						"rank_id":"27"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[28],
						"rank_id":"28"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[29],
						"rank_id":"29"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[30],
						"rank_id":"30"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[31],
						"rank_id":"31"
					}
				]},
				{
				"server_id":server[4],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[32],
						"rank_id":"32"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[33],
						"rank_id":"33"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[34],
						"rank_id":"34"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[35],
						"rank_id":"35"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[36],
						"rank_id":"36"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[37],
						"rank_id":"37"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[38],
						"rank_id":"38"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[39],
						"rank_id":"39"
					}
				]},
				{
				"server_id":server[5],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[40],
						"rank_id":"40"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[41],
						"rank_id":"41"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[42],
						"rank_id":"42"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[43],
						"rank_id":"43"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[44],
						"rank_id":"44"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[45],
						"rank_id":"45"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[46],
						"rank_id":"46"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[47],
						"rank_id":"47"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}
	
	
elif FLAGS.npu_nums == 7:
	rank = {
		"server_count":"7",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]},
				{
				"server_id":server[3],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[24],
						"rank_id":"24"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[25],
						"rank_id":"25"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[26],
						"rank_id":"26"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[27],
						"rank_id":"27"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[28],
						"rank_id":"28"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[29],
						"rank_id":"29"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[30],
						"rank_id":"30"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[31],
						"rank_id":"31"
					}
				]},
				{
				"server_id":server[4],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[32],
						"rank_id":"32"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[33],
						"rank_id":"33"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[34],
						"rank_id":"34"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[35],
						"rank_id":"35"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[36],
						"rank_id":"36"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[37],
						"rank_id":"37"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[38],
						"rank_id":"38"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[39],
						"rank_id":"39"
					}
				]},
				{
				"server_id":server[5],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[40],
						"rank_id":"40"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[41],
						"rank_id":"41"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[42],
						"rank_id":"42"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[43],
						"rank_id":"43"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[44],
						"rank_id":"44"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[45],
						"rank_id":"45"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[46],
						"rank_id":"46"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[47],
						"rank_id":"47"
					}
				]},
				{
				"server_id":server[6],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[48],
						"rank_id":"48"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[49],
						"rank_id":"49"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[50],
						"rank_id":"50"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[51],
						"rank_id":"51"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[52],
						"rank_id":"52"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[53],
						"rank_id":"53"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[54],
						"rank_id":"54"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[55],
						"rank_id":"55"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}
	
	
	
	
elif FLAGS.npu_nums == 8:
	rank = {
		"server_count":"8",
		"server_list":[
			{
				"server_id":server[0],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[0],
						"rank_id":"0"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[1],
						"rank_id":"1"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[2],
						"rank_id":"2"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[3],
						"rank_id":"3"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[4],
						"rank_id":"4"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[5],
						"rank_id":"5"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[6],
						"rank_id":"6"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[7],
						"rank_id":"7"
					}
				]},
				
				
				{
				"server_id":server[1],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[8],
						"rank_id":"8"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[9],
						"rank_id":"9"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[10],
						"rank_id":"10"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[11],
						"rank_id":"11"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[12],
						"rank_id":"12"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[13],
						"rank_id":"13"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[14],
						"rank_id":"14"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[15],
						"rank_id":"15"
					}
				]},
				{
				"server_id":server[2],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[16],
						"rank_id":"16"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[17],
						"rank_id":"17"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[18],
						"rank_id":"18"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[19],
						"rank_id":"19"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[20],
						"rank_id":"20"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[21],
						"rank_id":"21"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[22],
						"rank_id":"22"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[23],
						"rank_id":"23"
					}
				]},
				{
				"server_id":server[3],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[24],
						"rank_id":"24"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[25],
						"rank_id":"25"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[26],
						"rank_id":"26"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[27],
						"rank_id":"27"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[28],
						"rank_id":"28"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[29],
						"rank_id":"29"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[30],
						"rank_id":"30"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[31],
						"rank_id":"31"
					}
				]},
				{
				"server_id":server[4],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[32],
						"rank_id":"32"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[33],
						"rank_id":"33"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[34],
						"rank_id":"34"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[35],
						"rank_id":"35"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[36],
						"rank_id":"36"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[37],
						"rank_id":"37"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[38],
						"rank_id":"38"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[39],
						"rank_id":"39"
					}
				]},
				{
				"server_id":server[5],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[40],
						"rank_id":"40"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[41],
						"rank_id":"41"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[42],
						"rank_id":"42"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[43],
						"rank_id":"43"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[44],
						"rank_id":"44"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[45],
						"rank_id":"45"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[46],
						"rank_id":"46"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[47],
						"rank_id":"47"
					}
				]},
				{
				"server_id":server[6],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[48],
						"rank_id":"48"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[49],
						"rank_id":"49"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[50],
						"rank_id":"50"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[51],
						"rank_id":"51"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[52],
						"rank_id":"52"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[53],
						"rank_id":"53"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[54],
						"rank_id":"54"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[55],
						"rank_id":"55"
					}
				]},
				{
				"server_id":server[7],
				"device":[
					{
						"device_id":"0",
						"device_ip":rank_address[56],
						"rank_id":"56"
					},
					{
						"device_id":"1",
						"device_ip":rank_address[57],
						"rank_id":"57"
					},
					{
						"device_id":"2",
						"device_ip":rank_address[58],
						"rank_id":"58"
					},
					{
						"device_id":"3",
						"device_ip":rank_address[59],
						"rank_id":"59"
					},
					{
						"device_id":"4",
						"device_ip":rank_address[60],
						"rank_id":"60"
					},
					{
						"device_id":"5",
						"device_ip":rank_address[61],
						"rank_id":"61"
					},
					{
						"device_id":"6",
						"device_ip":rank_address[62],
						"rank_id":"62"
					},
					{
						"device_id":"7",
						"device_ip":rank_address[63],
						"rank_id":"63"
					}
				]}
				],
		"status":"completed",
		"version":"1.0"
	}
	
	
	
	
with open("rank_table.json", "w") as f:
	json.dump(rank, f)






